package com.example.gzysmartcity.viewmodel;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.blankj.utilcode.util.ThreadUtils;
import com.example.gzysmartcity.repository.model.CityPark;
import com.example.gzysmartcity.repository.remote.State;
import com.example.gzysmartcity.utils.NetworkUtil;

import java.util.List;

public class ParkViewModel extends ViewModel {
    MutableLiveData<State> parkliveData=new MutableLiveData<>();
    List<CityPark.DataBean> parks;

    public void getParkData(){
        ThreadUtils.executeByCached(new ThreadUtils.Task<CityPark>() {
            @Override
            public CityPark doInBackground() throws Throwable {
                return NetworkUtil.getInstance().get("CityPark/getAll?", null, CityPark.class, 0);
            }

            @Override
            public void onSuccess(CityPark result) {
                parks = result.getData();
                parkliveData.postValue(State.SUCCESS);
            }

            @Override
            public void onCancel() {

            }

            @Override
            public void onFail(Throwable t) {
                parkliveData.postValue(State.FAIL);
            }
        });
    }
    public MutableLiveData<State> getParkliveData(){
        return parkliveData;
    }

    public List<CityPark.DataBean> getParksList(){
        return parks;
    }

}
